import React from 'react'
import store from '../../store/store'

import {
  incrementAction,
  decrementAction,
  waitincrementAction,
} from '../../store/actions/countActions'

export default function Count() {
  const {count} = store.getState().count;      //拿到countReducer中的值
  const {movieList} = store.getState().movie;  //拿到movieReducer中的值


  //累加
  const incrementHandle = () => {
    incrementAction(1)
  }

  //累减
  const decrementHandle = () => {
    decrementAction(1)
  }

  //奇数累减
  const ifOddDecrementHandle = () => {
    if(count % 2 !==0 ){
      incrementAction(1)
    }
  }

  //等2秒累加
  const waitIncrementHandle = () => {
    store.dispatch(waitincrementAction(1))
  }


  return (
    <div>
        <h1>我是Count组件我的值是{count}</h1>
        <p>Movie组件的电影条数是{movieList.length}</p>
        <div>
            <button onClick = {incrementHandle}>累加</button>
            <button onClick = {decrementHandle}>累减</button>
            <button onClick = {ifOddDecrementHandle}>奇数累减</button>
            <button onClick = {waitIncrementHandle}>等2秒累加</button>
        </div>
    </div>
  )
}
